package com.stone.jms.beans;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.jms.Destination;
import javax.jms.Queue;

/**
 * Created by stone on 2017/7/28.
 * 生产者
 */
@Service(value = "producer")
@EnableScheduling
public class Producer {

    @Autowired
    private JmsMessagingTemplate jmsTemplate;

    @Autowired
    private Queue queue;

    @Scheduled(fixedDelay = 3000L)
    public void sendMessage() {
        this.jmsTemplate.convertAndSend(this.queue, "Hello world");
    }

    public void sendMessage2(Destination destination,String message) {
        jmsTemplate.convertAndSend(destination, message);
    }
}
